//加载公共样式
require('../../assets/css/index.less')

//服务器地址
const API = 'http://fitness.h5.itsource.cn:3701'

let dom = require('../../utils/dom')
const request = require('../../utils/request')

//字体图标
require('../../assets/fonts/iconfont.css')
//加载自己的样式
require('./course.less')

window.onload = () => {

    const startBtn=document.querySelector('#startBtn')
    const name=document.querySelector('#name')
    const calorie=document.querySelector('#calorie')
    const time=document.querySelector('#time')
    const peopleNum=document.querySelector('#peopleNum')
    const desc=document.querySelector('#desc')
    const frequency=document.querySelector('#frequency')
    const instrument=document.querySelector('#instrument')
    const imgUrl=document.querySelector('#imgUrl')
    const back=document.querySelector('#back')

    console.log(location.href);
    let courseID = (location.href).split('?')[1].split('=')[1]
    console.log(courseID);

    function getData() {
        request.get('/api/train/courseDetail',{
            params:{
                id:courseID
            }
        }).then(res => {
            console.log(res);
            let {data,errno}=res.data
            if(errno==0){
                name.textContent=data.name
                calorie.textContent=data.calorie
                time.textContent=data.time
                peopleNum.textContent=data.peoplenum
                desc.textContent=data.desc
                frequency.textContent=data.frequency
                instrument.textContent=data.instrument
                imgUrl.src=API+data.fragments[0].imgUrl

                //将视频存储
                localStorage.setItem('fragments', JSON.stringify(data.fragments))
            }
        })
    }
    getData()

    startBtn.addEventListener('click',function(){
        location.href='./play.html'
    })
    
    back.addEventListener('click',function(){
        history.go(-1)
    })

}